<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>同花顺个股新闻</title>
		<link href="css/text.css" rel="stylesheet" type="text/css" />
		<style type="text/css">				
			.fixedBox{
				border: 5px solid #555555;				
				white-space: normal;
			}
			.fixedBox::-webkit-scrollbar {
				width: 12px;     
				height: 12px;				
			}			
		</style>
	</head>
	<body>
		<div id="towrite" class="fixedBox" style="display:none;"></div>				
		<script type="text/javascript" src="js/json2html.js"></script>
		<script type="text/javascript" src="js/jquery.min.js"></script>
		<script>
			window.onload = function() {
				getSource();
				changeStyle();
			}
			
			function changeStyle() {
				var obj = document.getElementById("towrite");				
				obj.style.display= "block";
				obj.style.left = "0px"; 				
				obj.style.width = "98%";	
				//obj.style.height = "620px";		
				obj.style.fontSize ="14px";					
			}
			
			
			$(function() {
				setInterval(function() {
					getSource();
				},
				500);
			})
			
			Date.prototype.Format = function (fmt) {
				var o = {
				"M+": this.getMonth() + 1, //月份
				"d+": this.getDate(), //日
				"h+": this.getHours(), //小时
				"m+": this.getMinutes(), //分
				"s+": this.getSeconds(), //秒
				"q+": Math.floor((this.getMonth() + 3) / 3), //季度
				"S": this.getMilliseconds() //毫秒
				};
				if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
				for (var k in o)
				if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
				return fmt;
			};

			function getLocalTime(nS) {			          
				return new Date(parseInt(nS*1000)).Format("yyyy-MM-dd hh:mm:ss")
			}

			var gpdm = "";
			var gpmc = "";
			var dm ="";			
			function getSource() {								
				var u = decodeURI(window.location.href);								
				if(u.indexOf("##") > -1){
					var gp = u.split('##');				
					dm = gp[1];
					gpmc = gp[2];															
				}else{
					dm = "600000";
					gpmc = "浦发银行";					
				}
				
				if(dm != gpdm){				
					gpdm = dm;					
					var url = "https://m.0033.com/listv4/hs/" + dm + "_1.json"					
					var p = 1;
					var res = [];
					$.ajax({
						type: "get",
						url: url,
						dataType: "json",
						async : false,
						cache:false,
						timeout:3000,					
						success: function(data) {
							//alert(JSON.stringify(data))						
							//document.write(JSON.stringify(data));
							p = data.data.pages;
							res = data.data.pageItems;							
						}
					});
					//document.write(JSON.stringify(res));
					
					var div = document.getElementById('towrite');
					div.innerHTML = "<font size='3' style=color:#FFFF00;>个股新闻：<font size='2' color=#fff>&nbsp;&nbsp;&nbsp;&nbsp;" + gpdm + "&nbsp;&nbsp;" + gpmc + "</font></font>";					
					if(p > 1){
						for(var i = 2; i < p + 1; i++){
							var url = "https://m.0033.com/listv4/hs/" + dm + "_" + i + ".json"					
							var p = 1;
							var arr = [];
							$.ajax({
								type: "get",
								url: url,
								dataType: "json",
								async : false,
								cache:false,
								timeout:3000,					
								success: function(data) {
									//alert(JSON.stringify(data))						
									//document.write(JSON.stringify(data));
									p = data.data.pages;
									arr = data.data.pageItems;							
								}
							});
							res = res.concat(arr);
						}
					}
					//document.write(JSON.stringify(res));
					
					for(var i = 0; i < res.length; i++){
						var aa = res[i];
						var wz = aa.url;
						var title = aa.title;
						title = title.replace(/\n/g,"").replace(/"/g,"“");
						
						var rq = getLocalTime(aa.ctime);
						var lb = aa.label_type;
						
						var newdiv = document.createElement('div');	
						//newdiv.style.border= "1px solid #fff";
						newdiv.style.marginTop= "10px";						
						newdiv.style.width= "96%";	
						div.appendChild(newdiv);
						
						var newdiv1 = document.createElement('div');
						newdiv1.style.float= "left";						
						newdiv1.style.width= "75%";
						newdiv1.style.marginTop= "-5px";
						newdiv1.style.marginLeft= "-10px";
						newdiv.appendChild(newdiv1);
						newdiv1.innerHTML = "<li><a href='http://www.treeid/dlg" + wz + "' style='color:#FFDEAD;' onclick='changeCss(this,\"towrite\");'>" + title + "<a></li>";											 						

						var newdiv2 = document.createElement('div');
						newdiv2.style.float= "right";						
						newdiv2.style.width= "15%";
						//newdiv1.style.height= "60%";
						newdiv2.style.marginTop= "-5px";
						newdiv2.style.whiteSpace= "nowrap";
						newdiv.appendChild(newdiv2);						
						newdiv2.innerHTML =  "<span style=color:#F0FFFF;>" + lb + "</span><span style=padding-left:10px;color:#FFF;>" + rq + "</span>";
					
					}
					div.scrollTop = 0; //回到顶部
				}
			}
			
			function changeCss(obj,id){				
				var alist = document.getElementById(id).getElementsByTagName("a");					
				for(var i = 0; i < alist.length; i++){
					if(alist[i].innerText != "弹出显示"){
						alist[i].style.color = "#FFDEAD"; //给所有a标签赋原色
					}
				}
				obj.style.color = "#00FFFF"; //令当前标签高亮				
			}
			
		</script>	
	</body>
</html>